<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
      <ul>
        <li v-for="item in items" :key="item.id">
          <h3>
            {{ item.name }}
          </h3>
          <p>
            {{ item.minPrice}}
          </p>
          <img :src="item.pic" alt="">
        </li>
      </ul>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>

  <script>
   
  // 统一做配置
    axios.defaults.baseURL = "https://api.it120.cc/conner";
    axios.defaults.headers.a = 10;
    // 添加一个请求的拦截
axios.interceptors.request.use(function (config) {
    // 在请求发送之前可以做些事情
    console.log('请求发送了');
    console.log(config)
    config.headers.token = "hfwihfwi38ruhvcfie2jo";
    return config;
  }, function (error) {
    // 请求出错的拦截
    return Promise.reject(error);
  });

// 添加响应拦截
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });
    const vm = new Vue({
      el: '#app',
      data:{
        items:[]
      },
      created() {
        this.fetchItems();
      },
      methods:{
        fetchItems(){
          axios.post('/shop/goods/list',{
            categoryId:72399
          }).then(res=>{
            console.log(res)
            if(res.data.code === 0){
              this.items = res.data.data
            }
          })
        }
      }
    })
  </script>
</body>
</html>